<?php
declare (strict_types=1);

namespace app\api\controller;

use app\api\controller\Base;
use app\common\model\Coupon;
use app\common\model\User;
use app\common\model\UserSign as UserSignmodel;
use app\common\server\RedisLock as Lock;
use \think\Request;

class UserSign extends Base
{
    /**
     * 签到页面
     */
    public function index(Request $request)
    {
        $user = $this->getUser();

        //获取签到信息
        $data = UserSignmodel::getListByUserId($user['id']);
        $sign = [];
        $sign['days'] = $data[0];            //连续签到天数
        $sign['is_sign'] = $data[1];        //今日是否签到
        $config = getConfig('sign');
        $sign_info = [];                    //签到奖励信息
        $sign_info[] = $config['one_num'];
        $sign_info[] = $config['two_num'];
        $sign_info[] = $config['three_num'];
        $sign_info[] = $config['four_num'];
        $sign_info[] = $config['five_num'];
        $sign_info[] = $config['six_num'];
        $sign_info[] = $config['seven_num'];
        $sign['sign_info'] = $sign_info;

        return $this->renderSuccess("请求成功", compact('sign'));
    }

    /**
     * 签到
     */
    public function sign_add(Request $request)
    {
        $user = $this->getUser();
        $data = UserSignmodel::add($user['id']);
        if ($data != '今日您已签到') {
            return $this->renderSuccess($data['msg'], $data['data']);
        } else {
            return $this->renderError($data);
        }
    }

}